/**
 * Copyright (C) 2010-2013 Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.rocketmq.remoting;

import com.alibaba.rocketmq.remoting.exception.RemoteConnectException;
import com.alibaba.rocketmq.remoting.exception.RemoteSendRequestException;
import com.alibaba.rocketmq.remoting.exception.RemoteTimeoutException;
import com.alibaba.rocketmq.remoting.exception.RemoteTooMuchRequestException;
import com.alibaba.rocketmq.remoting.netty.NettyRequestProcessor;
import com.alibaba.rocketmq.remoting.protocol.RemoteCommand;

import java.util.List;
import java.util.concurrent.ExecutorService;


/**
 * 远程通信，Client接口
 *
 * @author shijia.wxr<vintage.wang@gmail.com>
 * @since 2013-7-13
 */
public interface RemoteClient extends RemoteService {
    /**
     * 更新服务提供者列表
     *
     * @param address 服务器地址（ip:端口）
     */
    public void updateServerAddressList(final List<String> address);

    public List<String> getServerAddressList();

    /**
     * 同步发送消息
     *
     * @param addr          要发送的服务器地址
     * @param request       请求的原生数据
     * @param timeoutMillis 发送超时的时间
     * @return
     */
    public RemoteCommand invokeSync(final String addr, final RemoteCommand request, final long timeoutMillis) throws InterruptedException, RemoteConnectException,
            RemoteSendRequestException, RemoteTimeoutException;

    /**
     * 发送异步消息
     *
     * @param addr           服务器地址
     * @param request        消息
     * @param timeoutMillis  超时时间
     * @param invokeCallback 回调函数
     */
    public void invokeAsync(final String addr, final RemoteCommand request, final long timeoutMillis,
                            final InvokeCallback invokeCallback) throws InterruptedException, RemoteConnectException,
            RemoteTooMuchRequestException, RemoteTimeoutException, RemoteSendRequestException;


    public void invokeOneway(final String addr, final RemoteCommand request, final long timeoutMillis)
            throws InterruptedException, RemoteConnectException, RemoteTooMuchRequestException,
            RemoteTimeoutException, RemoteSendRequestException;


    public void registerProcessor(final int requestCode, final NettyRequestProcessor processor,
                                  final ExecutorService executor);


//    public boolean isChannelWriteAble(final String addr);
}
